package com.msmall.community.common.action.wml;

import com.msmall.base.action.WMLBaseAction;
import com.msmall.base.model.OperationResult;
import com.msmall.base.util.Constants;
import com.msmall.community.common.OnlineUser;
import com.msmall.community.user.model.UserInfo;
import com.msmall.community.user.service.UserManager;

public class LoginAction extends WMLBaseAction {
	
	private static final long serialVersionUID = -1505680970768435816L;

	private String account;
	
	private String password;
	
	private UserManager userManager;

	public String go(){
		return SUCCESS;
	}
	public String login() {
		OperationResult authResult = userManager.authenticate(account, password);
		if (authResult.getCode() != OperationResult.CODE_SUCCESS) {
			addMessage(1, getText("sys.login.error"+authResult.getDesc()));
			return ERROR;
		}
		UserInfo userInfo = (UserInfo) authResult.getObj();
		OnlineUser.userAuthenticated(getUserid(), userInfo.getUserid(), getSession());
		gotoUrl = (String)getSession().getAttribute(Constants.GOTOURL);
		if (gotoUrl == null || "".equals(gotoUrl)) {
			gotoUrl = "/home.do";
		} else {
			getSession().removeAttribute(Constants.GOTOURL);
		}
		
		log.debug("gotoURL="+gotoUrl);
		return SUCCESS;
	}
	
	public void setUserManager(UserManager userManager) {
		this.userManager = userManager;
	}
	
	public String getPassword() {
		return password;
	}
	
	public void setPassword(String password) {
		this.password = password;
	}
	public String getAccount() {
		return account;
	}
	public void setAccount(String account) {
		this.account = account;
	}
}
